<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="text" id="input1" />
		
		<script>
			input1.onkeydown = function(e){
				console.log("键盘按下");
				console.log(e.key);
				console.log(e.keyCode);	
				
				if(e.keyCode != 8 && e.keyCode < 48 || e.keyCode > 57){
					event.preventDefault();
				}
			}
			
			input1.onkeyup = function(){
				console.log('键盘抬起');
			}
			input1.onkeypress = function(e){
				console.log('键盘按了');
			}
		</script>
	</body>
</html>
